package com.whz.enumdemo;

/**
 * @Author: sinosoft
 * @Description: 枚举结合策略模式
 * 在五个工作日中 超过正常8个小时的工作时间都会产生加班工资
 * 在节假日中所有工作都产生加班工资
 * @Date: Create in 18:50 2021/5/13
 * @Modified By:
 */
public enum PayrollDayStrategy {
    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,
    SATURDAY(PayType.WEEKEND), SUNDAY(PayType.WEEKEND);

    private final PayType payType;

    PayrollDayStrategy(PayType payType) {
        this.payType = payType;
    }

    PayrollDayStrategy() {
        this.payType = PayType.WEEKDAY;
    }

    int pay(int minutesWorked, int payRate) {
        return payType.pay(minutesWorked, payRate);
    }

    private enum PayType {
        WEEKDAY {
            @Override
            int overtimePay(int mins, int payRate) {
                return mins <= MINS_PER_SHIFT ?
                        0 : (mins - MINS_PER_SHIFT) * payRate / 2;
            }
        },
        WEEKEND {
            @Override
            int overtimePay(int mins, int payRate) {
                return mins * payRate / 2;
            }
        };
        abstract int overtimePay(int mins, int payRate);
        private static final int MINS_PER_SHIFT = 8 * 60;

        int pay(int minsWorked, int payRate) {
            int basePay = minsWorked * payRate;
            return basePay + overtimePay(minsWorked, payRate);
        }
    }




}
